function Category(serviceID){
	/* *
	 *	{
	 *		id:1,
	 *		name: 'category',
	 *		sonCount:10,
	 *		idLoaded:false 	// if all the article's informatino which belong to this
	 *						// category has been loaded, we set it true
	 * 		isChanged:true/false
	 *	}
	 */
	this.categories = [];
	this.SERVERCEID = serviceID;
}
Category.prototype.create = function( name, handler ){
	var $_this = this;
	ranidae.api.category.create(this.SERVERCEID, name, function(resultCode){
		var cat = {
			id:resultCode,
			name: name,
			sonCount:0,
			idLoaded:false};
		
		$_this.categories.push(cat);
		
		handler(resultCode);
	});
}
Category.prototype.rename = function( categoryId, newName, handler ){
	var $_this = this;
	var index = this.getIndex(categoryId);
	ranidae.api.category.rename(this.SERVERCEID, categoryId, newName, function(resultCode){
		$_this.categories[index].name = newName;
		handler(resultCode);
	});
}
Category.prototype.getIndex = function( categoryId ){
	var index = this.categories.length;
	
	while ( -1 < --index )
		if ( this.categories[index].id == categoryId*1 )
			break;
	
	if ( -1 == index )
		throw ('Could not find article ID! : ID:' + categoryId );
		
	return index;
}
Category.prototype.list = function( handler ){
	var $_this = this;
	ranidae.api.category.list(this.SERVERCEID, function( list ){
		$_this._addCategoryToList( list );
		handler($_this.categories);
	});
}
Category.prototype._addCategoryToList = function( list ){
	for ( var i=0; i<list.length; i++ ){
		var cat = {
			id:list[i].id,
			name: list[i].name,
			sonCount:list[i].son_count,
			isLoaded:false};
		
		this.categories.push(cat);
	}
}
Category.prototype.getInfo = function( categoryId ){
    var inforIndex = this.categories.length;

    while ( --inforIndex > -1 ){
        if ( this.categories[inforIndex].id == categoryId*1 )
            break;
    }

    return -1 == inforIndex ? null : this.categories[inforIndex];
}
